﻿<?php
/*
+--------------------------------------------------------------------------
|   phpBIZbiz v 2.0 full version
|   ========================================
|   by taft@wjl.cn
|   http://www.phpbiz.cn
|   all rights reserved
+---------------------------------------------------------------------------
|
|   > 
|   > 最后修改日期：2005-9-9
|   > 
|
+--------------------------------------------------------------------------
*/
class admin_functions
{

	var $html;
	var $page_instruction;
	var $page_title ="欢迎来到phpBIZ中文版管理面板";
	var $nav = array();
	var $base_url;

    
	function  admin_functions()
	{
		global $CONF,$INCOME;

		$this -> base_url = $CONF['admin_url']."admin.".$CONF['php_ext']."?";
	}
	
	function output()
	{   
		global $SKIN, $std , $ADMIN, $DB, $CONF;

		$DB -> db_close();
		
		$html =  $SKIN -> get_top($this->page_title, $this->page_instruction);
		$html .= $this -> html;
		$html .= $SKIN -> get_foot();
		
		/*-------------构造导航条---------------*/		
		if ( count($this->nav) > 0 )
		{
			foreach ( $this->nav as $idx => $links )
			{
				if ($links[0] != "")
				{
					$navigation[] = "<a href='{$this->base_url}&{$links[0]}' target='body'>{$links[1]}</a>";
				}
				else
				{
					$navigation[] = $links[1];
				}
			}
		}

		if ( count($navigation) > 0 )
		{
			$html = str_replace( "<!--NAV-->", $SKIN->wrap_nav( implode( " -&gt; ", $navigation ) ), $html );
		}
                       
		print $html;   // ready to fire!
		
		exit();
	}

	
	function menu()
	{   
		global $SKIN;
		
		$tree = $SKIN -> menu_tree();

		print $SKIN -> menu_top(). $tree. $SKIN -> menu_foot();

		exit();
	}

	function error( $error="" ) 
	{
		global $INCOME, $SKIN;
		
		$this->page_title  = "管理面板信息信息";
		$this->page_instruction = "&nbsp;";
		
		$this->html .= "<div class='tableborder'>
		                 <div class='maintitle'>当前操作面板信息</div>
		                 <div class='tdrow1' style='padding:8px'>
						  <span style='font-size:12px'>$error</span>
						 </div>
						</div>";
	
		$this->output();
		
	}
	
	function record_log( $action ="" )
	{
		global $DB, $INCOME , $SESS;

		$record_time = date( "Y-m-d H:i:s");
		$str = $DB->db_compile_fields( array(
													  'act'        => $INCOME['act'],
													  'code'       => $INCOME['code'],
													  'user_id'  => $SESS -> get_login_user_id(),
													  'log_time'      => $record_time,
													  'log_content'   => $action,
			                                          'log_ip' => $_SERVER[REMOTE_ADDR]
											)       );
											
		$DB->db_query("INSERT INTO biz_admin_log ({$str['fields']}) VALUES ({$str['value']})");
		
	}

	function done_screen($title, $link_text="", $link_url="") 
	{
		global $INCOME, $SKIN;
		
		$this->page_title  = $title;
		$this->page_instruction = "动作成功执行";
		
		$SKIN->td_header[] = array( "&nbsp;"  , "100%" );
		
		$this->html .= $SKIN->table_head("结果");
		
		$this->html .= $SKIN->td_basic( "<a href='{$this->base_url}{$link_url}' target='body'>返回： $link_text</a>", "center" );
		
		$this->html .= $SKIN->td_basic( "<a href='{$this->base_url}act=index' target='body'>返回：  phpBIZ中文自由版管理面板</a>", "center" );
										 
		$this->html .= $SKIN->table_end();
			
		$this->output();
	
	}

   function unlink_pic( $file_name,$thumb=0 )
   {
	   if( !is_array($file_name) ) return;
	   foreach( $file_name as $v )
	   {
		   unlink( $this->make_full_path($v,$thumb) );
	   }
	   return;
   }
   function recache()
   {
	 	@unlink("cache/index_cache.php");
		@unlink(ROOT_PATH."cache/cat_cache.php");
		@unlink(ROOT_PATH."cache/fee_cache.php");
		@unlink(ROOT_PATH."cache/level_cache.php");
   }
   function make_full_path($file_name,$thumb=0)  // mixed dir and url
   {
	   	global $CONF;
        if($CONF['single_upload_dir']==0)
		{
			$start = 5;
			if($thumb) $start += strlen($CONF['thumb_prefix']);
			$timestamp= substr($file_name,$start,10); 
			return $CONF['upload_url'].date("Y",$timestamp)."/".date("m",$timestamp)."/".$file_name;
		}else{
			return ROOT_PATH.$CONF['upload_url'].$file_name;
		}
   }
    function get_thumb($file_name)
   {
	   global $CONF;

	   $pathfile = $this -> make_full_path($file_name);
	   $thumbfile= $this -> make_full_path($CONF['thumb_prefix'].$file_name,1);
	   if(!@is_file($thumbfile))
	   {
		   $this -> _resize($thumbfile,$pathfile,"php","");
	   }
	   return $thumbfile;
   }

   //----------------- Add by 縮圖外掛 --------------------------- 
    function _resize($dest,$src,$imglib,$convert_path){ 
        
       if(!@is_file($src)) return;
	   
	   $quality=82;  //----JPG 壓縮品質 
        
       $image_info=getimagesize($src); 
       $srcSize_W=$image_info[0]; 
       $srcSize_H=$image_info[1]; 
        
       $img_aspect=$srcSize_W/$srcSize_H; 
        
       if( $srcSize_H > $srcSize_W*2 ) define(SMALL_IMAGE_HEIGHT,100);

	   if(SMALL_IMAGE_WIDTH>0){
          $destSize_W=SMALL_IMAGE_WIDTH; 
          $destSize_H=intval($destSize_W/$img_aspect); 
       }else if(SMALL_IMAGE_HEIGHT>0){
          $destSize_H=SMALL_IMAGE_HEIGHT; 
          $destSize_W=intval($destSize_H*$img_aspect); 
       }else{
          $destSize_W=100; 
          $destSize_H=intval($destSize_W/$img_aspect);
      }       
     
	  if($imglib=="php") { 
           //----------- With buildin php GD function -----------------------           
            
           $destImage = imageCreateTrueColor($destSize_W,$destSize_H); 
           
           //imageAntiAlias($destImage,true); 
           //------消鋸齒演算，因看不出效果，故移除以節省時間。 
                       
           switch ($image_info[2]) 
			{ 
                  case 1: //GIF 
                  $srcImage = imageCreateFromGif($src);  
				  imageCopyResampled($destImage, $srcImage, 0, 0, 0, 0,$destSize_W,$destSize_H,$srcSize_W,$srcSize_H); 
                  imagegif($destImage,$dest); 
                  //@copy ($src,$dest); 
                  break; 
                   
                  case 2: //JPEG 
                  $srcImage = imageCreateFromJpeg($src); 
                  //------- 進行縮圖演算--------------- 
                  imageCopyResampled($destImage, $srcImage, 0, 0, 0, 0,$destSize_W,$destSize_H,$srcSize_W,$srcSize_H); 
                  imageJpeg($destImage,$dest,$quality); 
                  break; 
                   
                  case 3: //PNG 
                  $srcImage = imageCreateFromPng($src); 
                  //------- 進行縮圖演算--------------- 
                  imageCopyResampled($destImage, $srcImage, 0, 0, 0, 0,$destSize_W,$destSize_H,$srcSize_W,$srcSize_H); 
                  imagePng($destImage,$dest);  
                  break; 
                   
                  default: 
                  return false; 
                  break; 
           } 
           if($srcImage)  imagedestroy($srcImage); 
           if($destImage) imagedestroy($destImage);      
                 
        }else{ 
           @copy ($src,$dest); 
        } 
      }

}

class session
{

    var $session_id;
	var $user_id;
	
	function session()
	{
		session_start();
		$this -> session_id = session_id();
		
	}
	function is_login()
	{
		return $_SESSION['login'];
	}

	function set_login($user_id)
	{
		$_SESSION['login'] = 1 ;
		$_SESSION['user_id'] = $user_id;
	}

	function get_login_user_id()
	{
		return $_SESSION['user_id'];
	}

	function get_session_id()
	{
		return $this -> session_id;
	}
    
	function set_logout()
	{
			$_SESSION = array() ; //unset the session 
			$session_id = 0 ;
			session_destroy();
	}
}
?>